#!/usr/bin/env python
# -*- coding: utf-8 -*-

import time
from .utils.control import Control
from .utils import tools
import os
import logging  # 引入logging模块
logger = logging.getLogger()


# 模拟 从机程序


def main():
    conf_file = tools.get_config()
    print('conf_file', conf_file)

    # 读取配置文件, 获取deivce code, 作为日志文件的文件名
    # device_code = conf_file['options']['code']
    tools.set_logging('salve_mock')

    # 读取配置文件, 获取 串口号
    conf_path = os.getcwd() + '/dev_conf/'

    conf_name = conf_path + 'gateway.conf'
    ports = tools.get_config(conf_name)
    # print('ports:', ports)
    port = ports['options']['slave_port']
    print('port is: ', port)

    # 读取配置文件, 获取 sensors, 模拟生成 采样数据时, 取这些传感器
    sensor_data = tools.get_csv_data()
    print('sensor_data:', sensor_data)
    Control(dev=port, host='guest', sensors=sensor_data)

    logger.info('loop to wait called by host')
    while 1:
        time.sleep(1000)
